<template>
	<view class="ListOfPatients">
		<Head class='HeadClass' :headShow="true" @click.native="showCS"></Head>
		<view class="ListOfPatients_BT">
			<view class="Patients_BT">
				<view class="ListOfPatientsBT_item" v-for="(item,index) in list" :key='index'
					style="margin-bottom: 10px;">
					<u-form labelAlign="right">
						<u-form-item prop="name" style="padding: 0 6px;">
							<view class="view-item">
								<text class="ListOfPatientsBTItem_textT">{{item.children[0].bedid}}</text>
								<view class="ListOfPatientsBTItem_text">
									{{item.children[0].pname}}
								</view>
							</view>
							<view class="view-item1">
								<view class="ListOfPatientsBTItem_textT textT1">
									{{item.children[0].mrn}}
								</view>
								<view v-if="item.children[0].specialflag=='7'|| item.children[0].specialflag=='8'"
									class="" style="margin-left: 10px; color: red;">
									{{item.children[0].specialflag=='7'?'TPN': item.children[0].specialflag=='8'?'化疗':item.children[0].specialflag}}
								</view>
							</view>
							<view class="Iage"></view>
						</u-form-item>
					</u-form>
					<view class="ListOfPatientsBT_center">
						<view class="ListOfPatientsBT-center-bottom"
							v-if="item.children[0].mark && item.children[0].mark.trim() != ''">
							{{item.children[0].mark}}
						</view>
						<view class="BT_center_remark">
							<view class="remark_state"
								v-if="item.children[0].examinationTypeIndex ||item.children[0].examinationTypeIndex==1">
								✔
							</view>
							<view class="remark_state" v-else>
								{{item.children[0].exeflag}}
							</view>
							<view class=""
								:style="{'background':bgColorted(item.children[0]),'color':Colorted(item.children[0])}">
								<view class="" v-for="(el,ind) in item.children" :key="ind">
									{{el.remark + (el.dosage.trim() ? '【'+el.dosage+'】' : el.dosage)}}
								</view>
							</view>
						</view>
						<view class="BT_center">
							<text class="text"
								v-if="item.children[0] &&item.children[0].realsent">{{item.children[0].realsent+'.0'}}</text>
							<view class="BT_center_hosder">
								<text>{{item.children[0].admissionname}}</text>
								<text style="margin-left: 5px;">{{item.children[0].empname}}</text>
							</view>
							<text class="BT_date">{{item.children[0].plandate}}</text>
						</view>
						<view class="ListOfPatientsBT-center-bottom" v-if="item.children[0].yuanyin">
							{{item.children[0].yuanyin}}
						</view>
					</view>
				</view>
			</view>
		</view>
		<scan-code @scanCodeId="scanCodeId" value="执行医嘱列表" v-if="showScanCode"></scan-code>
		<!-- 普通口服药弹框 -->
		<loop-medication v-for="(item,index) in messageList" :show="item.loopShow &&index==messageList.length-1"
			:key="index" :reportObj="medicationFun(item)" :teshuarray="teshuarray" :radiolist="radiolist"
			@loopTion="loopTion">
		</loop-medication>
		<!--双签弹框-->

		<double-sign v-for="(item,index) in doubleList" :key="item.remark" :show="item.show&&index==doubleList.length-1"
			:reportObj="singEd(item)" :teshuarray="teshuarray" @cancelTails="cancelTails" :radiolist="radiolist">
		</double-sign>
		<!-- 麻醉药 -->

		<mazuiyao v-for="(item,index) in mayList" :key="item.remark" :show="item.mayaoShow&&index==mayList.length-1"
			:reportObj="mayObj(item)" :teshuarray="teshuarray" :radiolist="radiolist" @mayaoTion="mayaoTion"></mazuiyao>
		<!-- 收费弹框 -->
		<bullet-frame :show="frameShow" :reportObj="frameObj" @bulletTion="bulletTion" :key="headkey"></bullet-frame>

		<uni-popup ref="popup" type="center">
			<view class="" v-for="(t,i) in list" :key="i">
			
				<text>{{t.children[0]}}</text>
			</view>
		</uni-popup>


	</view>
</template>

<script>
	import Head from '../../components/html/head.vue'
	import suspensionBall from '../../components/html/xuanfuqiu.vue'
	import scanCode from "../../components/html/scan-code.vue"
	import doubleSign from "@/components/html/doubleSign.vue"
	import loopMedication from "@/components/html/loopMedication.vue"
	import mazuiyao from "@/components/html/mazuiyao.vue"
	import testtest from "@/components/js/hexiii-nfc.js"
	import {
		ScanPatientinfo,
		Scan_yizhu_list,
		EMR_Nursing_ScanPSaveOrder,
		EMR_Nursing_ScanPSaveOrder_NS1,
		Common_CheckUsePassword
	} from '../../api/user.js'
	import bulletFrame from "@/components/html/bulletFrame.vue"
	import {
		mapMutations,
		mapState
	} from "vuex";
	export default {
		components: {
			Head,
			suspensionBall,
			scanCode,
			doubleSign,
			loopMedication,
			bulletFrame,
			mazuiyao
		},
		data() {
			return {
				form: {
					name: '',
				},
				showScanCode: true,
				scrollTop: 0,
				headkey: 0,
				examinationTypeIndex: 0,
				list: [],
				arr: [],
				show: false,
				reportObj: {},
				loopShow: false,
				loopObj: {},
				frameShow: false,
				frameObj: {},
				radiolist: [{
						name: '完成用药',
						id: 'end',
					},
					{
						name: '未用药',
						id: 'mid',
					}
				],
				radiolist1: [{
						name: '完成用药',
						id: 'end',
					},
					{
						name: '恢复用药',
						id: 'start',
					},
					{
						name: '中断用药',
						id: 'mid',
					}
				],
				radiolist2: [{
						name: '完成采集',
						id: 'end',
					},
					{
						name: '恢复采集',
						id: 'start',
					},
					{
						name: '中断采集',
						id: 'mid',
					}
				],
				mayaoShow: false,
				mayList: [],
				// mayObj: {},
				dataResult: [],
				isNum: false,
				listKun: [],
				messageList: [],
				num: 0,
				cs: 0,
				doubleList: [],
				teshuarray: [{
						label: '患者病情变化',
						value: 0
					},
					{
						label: '医嘱更改',
						value: 1
					},
					{
						label: '外出检查',
						value: 2
					},
					{
						label: '患者手术',
						value: 3
					},
					{
						label: '病人拒绝',
						value: 4
					},
					{
						label: '血透前停药',
						value: 5
					},
					{
						label: '其他',
						value: 6
					}
				]
			};
		},

		destroyed() {
			this.showScanCode = false
			uni.removeStorageSync('scanningArray')
			testtest.removeFun()
		},
		onShow() {
			//#ifdef APP-PLUS
			this.testNFC()
			// #endif
		},
		onLoad() {

			this.arr = uni.getStorageSync('scanningArray')

			if (this.arr) {
				this.list = this.alpha_sort(this.arr)
				this.dataBindUi(this.arr)
			}
		},
		computed: {
			...mapState('user', ["userInfo", "deleteObj", "scanningArray", "passObj"]),
			bgColorted(data) {
				return data => {
					return data.drugtest == '1' ? 'yellow' : data.drugtest == 'E' ? 'red' : data.drugtest ==
						'PMR' ? 'GREEN' : ''
				}
			},
			Colorted(data) {
				return data => {
					return data?.riskflag?.trim() == '1' ? 'blue' : ''
				}
			},
			medicationFun(list) {
				return list => {
					let a = this.alpha_sort(this.messageList)
					let b = a.map((item, index) => {
						if (item?.children.length > 1) {
							return item
						} else {
							return this.alpha_sort([list])[0]
						}
					})
					if (b[0].children.length > 0) {
						return b[0]
					} else {
						return this.alpha_sort([list])[0]
					}
				}
			},
			singEd(data) {
				return data => {
					let a = this.alpha_sort(this.doubleList)
					console.log(a);
					let b = a.map((item, index) => {
						if (item?.children.length > 1) {
							return item
						} else {
							return this.alpha_sort([data])[0]
						}
					})
					if (b[0].children.length > 0) {
						return b[0]
					} else {
						return this.alpha_sort([data])[0]
					}
				}
			},
			mayObj(obj) {
				return obj => {
					let a = this.alpha_sort(this.mayList)
					console.log(a);
					let b = a.map((item, index) => {
						if (item?.children.length > 1) {
							return item
						} else {
							return this.alpha_sort([obj])[0]
						}
					})
					if (b[0].children.length > 0) {
						return b[0]
					} else {
						return this.alpha_sort([obj])[0]
					}
				}
			}
		},
		methods: {
			...mapMutations("user", ["set_scanningArray"]),
			scroll(e) {
				//记录scroll  位置
				this.oldScrollTop = e.detail.scrollTop
			},
			// 双签
			cancelTails(value, data, title, yuanyin) {
				this.list.map((item, index) => {
					item.children.map((el, ind) => {
						if (el.remark == data[0].remark && el.plandate == data[0].plandate && el.setno ==
							data[0].setno) {
							if (title == 'queren') {
								el.examinationTypeIndex = 1
							} else if (title == 'shibai') {
								el.examinationTypeIndex = 0
								el.yuanyin = yuanyin
							} else {
								this.list.splice(index, 1)
							}
						}
					})
				})
				this.doubleList = this.resArr(this.doubleList, data, 'show')

				console.log(this.doubleList, 'this.doubleList');
			},
			resArr(arr1, arr2, value) {
				let a = arr1.filter((v) => arr2.every((val) => val.setno != v.setno));
				a.map(item => {
					item[value] = true
				})
				return a
			},
			// 普通口服药
			loopTion(value, data, title, yuanyin) {
				console.log(yuanyin);
				this.list.map((item, index) => {
					item.children.map(el => {
						if (el.remark == data[0].remark && el.plandate == data[0].plandate && el.setno ==
							data[0].setno) {
							if (title == 'queren') {
								el.examinationTypeIndex = 1
							} else if (title == 'shibai') {
								el.examinationTypeIndex = 0
								el.yuanyin = yuanyin
							} else {
								this.list.splice(index, 1)
							}
						}
					})
				})
				this.messageList = this.resArr(this.messageList, data, 'loopShow')
				// this.messageList = this.alpha_sort(this.messageList)
				// this.messageList?.map((item, index) => {
				// 	item?.children.map(el => {
				// 		if (el.remark == data[0].remark && el.plandate == data[0].plandate && el.setno ==
				// 			data[0].setno) {
				// 			this.messageList.splice(index, 1)
				// 		}
				// 	})
				// 	console.log(this.messageList, '1111111111111');
				// })
			},
			//麻药
			mayaoTion(value, data, title, yuanyin) {
				this.list.map((item, index) => {
					item.children.map(el => {
						if (el.remark == data[0].remark && el.plandate == data[0].plandate && el.setno ==
							data[0].setno) {
							if (title == 'queren') {
								el.examinationTypeIndex = 1
							} else if (title == 'shibai') {
								el.examinationTypeIndex = 0
								el.yuanyin = yuanyin
							} else {
								this.list.splice(index, 1)
							}
						}
					})
				})
				this.mayList = this.resArr(this.mayList, data, 'mayaoShow')
			},
			//收费
			bulletTion(value, data, title, iRtun) {
				this.list.map((item, index) => {
					item.children.map(el => {
						if (el.remark == data[0].remark && el.plandate == data[0].plandate && el.setno ==
							data[0].setno) {
							if (title == 'queren') {
								el.iMark = iRtun
							} else {
								this.list.splice(index, 1)
								if(this.list.length==0){
									uni.navigateBack({
										delta: 1, //返回层数，2则上上页
									})
								}
							}
						}
					})
				})
				// if (num) {
				// 	console.log(this.arr, this.list);
				// 	this.list = this.list.splice(this.arr.length - 1, 1)
				// }
				this.frameShow = value
			},
			async testNFC() {
				//这里用异步获取读取到的NFC数据
				let user = uni.getStorageSync('userInfo')
				await testtest.listenNFCStatus(false).then(async (value) => {
					if (!value) {
						return
					}
					// const data = {
					// 	HosKind: user.hoscode,
					// 	deptbed: user.HosKind,
					// 	iotcode: value
					// }
					// const res = await this.$http.PcaseIotcode(data)


					uni.request({
						url: 'http://20.21.9.38:8022/smartcare/iconMain/queryByComId?comId=' +
							value, //接口地址。url
						method: "get", //传输类型
						success: (res) => {
							if (res.data.success) {

								if (res.data.data.ptInfoIndex != null) {
									this.scanCodeId(res.data.data.ptInfoIndex.mrn, '执行医嘱列表')
								} else {
									uni.showToast({
										title: '未找到该绑定手环的病人信息！', //显示的文字
										// duration: 3000, //显示多少时间，默认1500毫秒
										icon: "none", //自定义显示的图标，默认成功success，错误error,加载loading，不显示图标是none
										mask: true
									})
								}
							}
						}
					});

				})
			},
			async scanCodeId(id, value) {
				console.log(id, value, '扫描数据');
				if (value != '执行医嘱列表') {
					return
				}
				try {
					let idCode = Number(id) % 1 === 0
					let a = []
					// 扫描病历号
					this.list.map((item, index) => {
						item.children.map((el, ind) => {
							if (el.examinationTypeIndex == 1) {
								return
							} else {
								a.push(el)
							}
						})
					})
					if (String(id).length < 12) {
						this.isNum = false
						const obj = uni.getStorageSync('deleteObj')
						if (obj.MRN == id) {
							if (this.list.length == 0 || a.length == 0) {
								uni.showToast({
									title: '请重扫医嘱再执行！', //显示的文字
									duration: 2000, //显示多少时间，默认1500毫秒
									icon: "none", //自定义显示的图标，默认成功success，错误error,加载loading，不显示图标是none
									mask: true
								})
								return
							} else {
								this.arr = a
								this.medicalRecord(id)
							}
						} else {
							uni.showToast({
								title: "患者身份错误，请仔细核对！", //显示的文字
								duration: 3000, //显示多少时间，默认1500毫秒
								icon: "none", //自定义显示的图标，默认成功success，错误error,加载loading，不显示图标是none
								mask: true
							})
						}
						console.log(1, this.arr);
					} else {
						// 扫码医嘱号
						if (this.arr.length == 0) {
							this.arr = []
						}
						this.isNum = true
						this.arr = a
						this.doctorsOrder(id)
						console.log(2);
					}
				} catch (e) {
					//TODO handle the exception
				}
			},
			async medicalRecord(value) {
				try {
					// if (!this.isNum) {
					let what = 0;
					let messageList = [];
					let doubleList = [];
					let mayList = [];

					let promise = this.arr.map((item, index) => {
						let obj = {}
						return new Promise(async (resolve, reject) => {
							if (item.exeflag == '0') {
								if (item.mazuiflag == '1') {
									what = 1;
									obj = JSON.parse(JSON.stringify(item));
									obj.mayaoShow = true;
									mayList.push(obj)
									setTimeout(() => {
										resolve({
											res: mayList,
											type: what
										})
									})
								} else if (item.specialflag == '1' || item.specialflag == '3' ||
									item.specialflag == '8') {
									what = 2;
									console.log(obj, 'obj')
									obj = JSON.parse(JSON.stringify(item));
									obj.show = true
									doubleList.push(obj)
									setTimeout(() => {
										resolve({
											res: doubleList,
											type: what
										})
									})
								} else if (item.orderflag == 'BDT') {
									what = 4;
									const sReult = await this.EMR_Nursing_ScanPSaveOrder_NS1Fun(
										item)
									resolve({
										res: sReult,
										type: what
									})
								} else {
									if (item.admission.trim() == 'PO') {
										what = 5;
										obj = JSON.parse(JSON.stringify(item));
										obj.loopShow = true
										messageList.push(obj)
										setTimeout(() => {
											resolve({
												res: messageList,
												type: what
											})
										})
									} else {
										what = 4;
										// 直接执行
										const sReult = await this
											.EMR_Nursing_ScanPSaveOrder_NS1Fun(item)
										resolve({
											res: sReult,
											type: what
										})
									}
								}
							} else
							if (item.exeflag == '1' && (item.orderflag == 'BDT')) {
								what = 4
								const sReult = await this.EMR_Nursing_ScanPSaveOrder_NS1Fun(item)
								resolve({
									res: sReult,
									type: what
								})
							} else {
								what = 4;
								// 直接执行
								const sReult = await this
									.EMR_Nursing_ScanPSaveOrder_NS1Fun(item)
								resolve({
									res: sReult,
									type: what
								})
							}

						})
					})
					let ptkfyShow = false;
					let bdtShow = false;
					const proResult = await Promise.all(promise)
					console.log(proResult, 'proResult');
					for (let i = 0; i < proResult.length; i++) {
						
						switch (proResult[i].type) {
							case 1: // 麻醉
								this.mayList = mayList
								break;
							case 2: // 1,3,8 双签名的
								this.doubleList = doubleList
								break;
							case 3: // BDT双签名
								//BDT执行改成刷第一次执行第二次核对
								break;
							case 4: // 普通的正常直接执行
								if (proResult[i]?.res[0]?.result == '1') {
									ptkfyShow = true
									this.arr[i].examinationTypeIndex = 1
									this.list = this.alpha_sort(this.arr)
								} else if (proResult[i]?.res[0]?.result == '2') {
									this.arr[i].examinationTypeIndex = 1
									ptkfyShow = true
									this.arr.map(item => {
										item.yuanyin = '输血核对成功！'
									})
									this.list = this.alpha_sort(this.arr)
									// uni.showToast({
									// 	title: "医嘱执行成功！", //显示的文字
									// 	duration: 2000, //显示多少时间，默认1500毫秒
									// 	icon: "none", //自定义显示的图标，默认成功success，错误error,加载loading，不显示图标是none
									// 	mask: true
									// })
								} else {
									ptkfyShow = false
									uni.showToast({
										title: proResult[i].res[0]?.result, //显示的文字
										duration: 2000, //显示多少时间，默认1500毫秒
										icon: "none", //自定义显示的图标，默认成功success，错误error,加载loading，不显示图标是none
										mask: true
									})
									return
								}
								break;
							case 5: // 普通的口服药物执行
								this.messageList = messageList
								break;
							default:
								return
						}

					}


					if (ptkfyShow) {
						uni.showToast({
							title: "医嘱执行成功！", //显示的文字
							duration: 1000, //显示多少时间，默认1500毫秒
							icon: "none", //自定义显示的图标，默认成功success，错误error,加载loading，不显示图标是none
							mask: true
						})
					}


					// for (let i = 0; i < this.arr.length; i++) {
					// 	if (this.arr[i].exeflag == '0') {
					// 		if (this.arr[i].mazuiflag == '1') {
					// 			what = 1;
					// 			obj = this.arr[i];
					// 			obj.mayaoShow = true
					// 			this.mayList.push(obj)
					// 		} else if (this.arr[i].specialflag == '1' || this.arr[i].specialflag == '3' || this
					// 			.arr[i].specialflag == '8') {
					// 			what = 2;
					// 			obj = this.arr[i];
					// 			obj.show = true
					// 			this.doubleList.push(obj)
					// 		} else if (this.arr[i].orderflag == 'BDT') {
					// 			what = 4;
					// 			const sReult = await this.EMR_Nursing_ScanPSaveOrder_NS1Fun(this.arr[i])
					// 			let reg = new RegExp("[\\u4E00-\\u9FFF]+", "g")
					// 			if (reg.test(sReult[0].result)) {
					// 				obj = sReult;
					// 			} else {
					// 				this.arr[i].examinationTypeIndex = 1
					// 				this.listKun = this.arr
					// 			}
					// 			// 直接执行
					// 			obj = sReult;
					// 		} else {
					// 			if (this.arr[i].admission.trim() == 'PO') {
					// 				what = 5;
					// 				obj = this.arr[i];
					// 				obj.loopShow = true
					// 				this.messageList.push(obj)
					// 			} else {
					// 				what = 4;
					// 				// 直接执行
					// 				const sReult = await this.EMR_Nursing_ScanPSaveOrder_NS1Fun(this.arr[i])
					// 				let reg = new RegExp("[\\u4E00-\\u9FFF]+", "g")
					// 				if (reg.test(sReult[0].result)) {
					// 					obj = sReult;
					// 				} else {
					// 					this.arr[i].examinationTypeIndex = 1
					// 					this.listKun = this.arr
					// 				}
					// 				obj = sReult;
					// 			}
					// 		}
					// 		console.log(what, obj);
					// 		this.sendMessage(what, obj, i);
					// 	} else if (this.arr[i].exeflag == '1' && this.arr[i].orderflag == 'BDT') {
					// 		what = 4;
					// 		const sReult = await this.EMR_Nursing_ScanPSaveOrder_NS1Fun(this.arr[i])
					// 		let reg = new RegExp("[\\u4E00-\\u9FFF]+", "g")
					// 		if (reg.test(sReult[0].result)) {
					// 			obj = sReult;
					// 		} else {
					// 			this.arr[i].examinationTypeIndex = 1
					// 			this.listKun = this.arr
					// 		}
					// 		obj = sReult;
					// 		this.sendMessage(what, obj);
					// 	} else {
					// 		console.log('111111111111111111111111111');
					// 	}
					// }
					// }
				} catch (e) {
					//TODO handle the exception
				}
			},
			async doctorsOrder(id) {
				try {
					// 添加病人医嘱
					const user = uni.getStorageSync('userInfo')
					const obj = uni.getStorageSync('deleteObj')
					const content = id.split('|')
					const data = {
						HosKind: user.hoscode,
						dobarcode: content[0],
						sOperdept: user.HosKind,
						sOperJp: user.sPassword
					}
					const res = await this.$http.Scan_yizhu_list(data);
					if (this.isNum) {
						if (res == null || res.length <= 0) {
							uni.showToast({
								title: '医嘱已经执行或未找到！', //显示的文字
								duration: 2000, //显示多少时间，默认1500毫秒
								icon: "none", //自定义显示的图标，默认成功success，错误error,加载loading，不显示图标是none
								mask: true
							})
						} else {
							let proof = false;
							var reslist;
							res.map((item, i) => {
								if (item.result != '1') {
									reslist = res.splice(i, 1);
									proof = true;
									return;
								}
							})
							if (!proof) {
								this.sacnHandler(res)
							} else {
								uni.showToast({
									title: reslist[0].result, //显示的文字
									duration: 2000, //显示多少时间，默认1500毫秒
									icon: "none", //自定义显示的图标，默认成功success，错误error,加载loading，不显示图标是none
									mask: true
								})
							}

						}
					}
				} catch (e) {
					//TODO handle the exception
				}

			},
			async EMR_Nursing_ScanPSaveOrder_NS1Fun(obj) {

				let user = uni.getStorageSync('userInfo')
				const data = {
					HosKind: user.hoscode,
					sExemode: 'PDA扫描',
					mrn: obj.mrn,
					stay: 'I',
					series: obj.series,
					orderdordnarray: obj.orderdordn,
					bedid: obj.bedid,
					pname: obj.pname,
					operdept: user.HosKind,
					operjp: user.sUserid,
					iMark: obj.iMark,
					iautocharge: obj.iautocharge,
					exeflag3: ''
				}
				uni.showToast({
					title: '正在执行...', //显示的文字
					// duration: 1500, //显示多少时间，默认1500毫秒
					icon: "loading", //自定义显示的图标，默认成功success，错误error,加载loading，不显示图标是none
				})

				const res = await this.$http.EMR_Nursing_ScanPSaveOrder_NS1(data)
				uni.hideToast();

				return res
			},
			sendMessage(value, obj, setNum) {
				let i = 0;
				switch (value) {
					case 1: // 麻醉
						return;
					case 2: // 1,3,8 双签名的
						return;
					case 3: // BDT双签名
						//BDT执行改成刷第一次执行第二次核对
						return;
					case 4: // 普通的正常直接执行
						if (obj[0].result == '1') {
							this.list = this.alpha_sort(this.listKun)
							console.log('普通的正常直接执行')
							uni.showToast({
								title: "医嘱执行成功！", //显示的文字
								duration: 1000, //显示多少时间，默认1500毫秒
								icon: "none", //自定义显示的图标，默认成功success，错误error,加载loading，不显示图标是none

							})
						} else if (obj[0].result == '2') {
							this.listKun.map(item => {
								item.yuanyin = '输血核对成功！'
							})
							this.list = this.alpha_sort(this.listKun)
							uni.showToast({
								title: "医嘱执行成功！", //显示的文字
								duration: 1000, //显示多少时间，默认1500毫秒
								icon: "none", //自定义显示的图标，默认成功success，错误error,加载loading，不显示图标是none

							})
						} else {
							uni.showToast({
								title: obj[0].result, //显示的文字
								duration: 2000, //显示多少时间，默认1500毫秒
								icon: "none", //自定义显示的图标，默认成功success，错误error,加载loading，不显示图标是none

							})
							return
						}
						return;
					case 5: // 普通的口服药物执行
						return;
				}
			},
			async sacnHandler(res) {
				if (this.arr.length == 0) {
					let arr = uni.getStorageSync('passObj')
					if ((arr.pname.trim() == res[0].pname.trim()) && (arr.bedid.trim() == res[0].bedid.trim())) {
						let UiShow = await this.dataBindUi(res)
						if (!UiShow) {
							res.map(item => {
								this.arr.push(item)
							})
						}
						this.list = this.alpha_sort(this.arr)
						return
					} else {
						uni.showToast({
							title: "不是当前病人的医嘱!", //显示的文字
							duration: 2000, //显示多少时间，默认1500毫秒
							icon: "none", //自定义显示的图标，默认成功success，错误error,加载loading，不显示图标是none
							mask: true
						})
						return
					}
				}
				let cietye = this.arr.filter((item) => {
					return (item.bedid == res[0].bedid) && (item.orderno == res[0].orderno) && (item
						.plandate == res[0].plandate)
				})
				if (cietye.length > 0) {
					uni.showToast({
						title: "当前医嘱已经在列表中！", //显示的文字
						duration: 2000, //显示多少时间，默认1500毫秒
						icon: "none", //自定义显示的图标，默认成功success，错误error,加载loading，不显示图标是none
						mask: true
					})
					return
				} else {
					let bistylist = this.arr.filter(item => {
						return (item.pname.trim() == res[0].pname.trim()) && (item.bedid.trim() == res[0].bedid
							.trim())
					})
					if (bistylist.length > 0) {
						let arr = uni.getStorageSync('passObj')
						if ((arr.pname.trim() == res[0].pname.trim()) && (arr.bedid.trim() == res[0].bedid.trim())) {
							let UiShow = await this.dataBindUi(res)
							if (!UiShow) {
								res.map(item => {
									this.arr.push(item)
								})
								this.list = this.alpha_sort(this.arr)
								this.arr.map((item, index) => {
									if (item.orderflag == 'BDT' && res[index].orderflag != 'BDT') {
										uni.showToast({
											title: "当前存在输血医嘱，不能执行其他类型的医嘱！", //显示的文字
											duration: 2000, //显示多少时间，默认1500毫秒
											icon: "none", //自定义显示的图标，默认成功success，错误error,加载loading，不显示图标是none
											mask: true
										})
										return
									}
									if (item.orderflag != 'BDT' && res[index].orderflag == 'BDT') {
										uni.showToast({
											title: "输血医嘱请单独执行!", //显示的文字
											duration: 2000, //显示多少时间，默认1500毫秒
											icon: "none", //自定义显示的图标，默认成功success，错误error,加载loading，不显示图标是none
											mask: true
										})
										return
									}
								})
							}
						} else {
							uni.showToast({
								title: "不是当前病人的医嘱!", //显示的文字
								duration: 2000, //显示多少时间，默认1500毫秒
								icon: "none", //自定义显示的图标，默认成功success，错误error,加载loading，不显示图标是none
								mask: true
							})
							return
						}
					} else {
						uni.showToast({
							title: "不是当前病人的医嘱!", //显示的文字
							duration: 2000, //显示多少时间，默认1500毫秒
							icon: "none", //自定义显示的图标，默认成功success，错误error,加载loading，不显示图标是none
							mask: true
						})
						return
					}
				}
			},
			dataBindUi(data) {
				data.map(item => {
					if (item.iMark != '' && item.iMark.indexOf("|") != -1) {
						this.frameObj = this.alpha_sort([item])[0]
						this.headkey++;
						this.frameShow = true
					} else {
						return false
					}
				})
			},
			alpha_sort(target) {
				let obj = {},
					result = [],
					resget = [],
					resLi = [];
				target.map((item, index) => {
					let key = item.setno;
					if (key == 0) {
						resget.push({
							children: [item]
						});
						return
					}
					//如果有这个key，就push一个对象
					if (obj[key]) {
						obj[key].push(item);
						//如果没有这个key，就把对象设置成数组格式（方便后面push进去）
					} else {
						obj[key] = [item];
					}
				});
				//根据obj中有几个对象，挨个push进去，组成最后的数组
				for (const key in obj) {
					// console.log(obj[key]);
					const element = obj[key];
					let Arrye = this.checkRepeat(element, 'remark')
					if (Arrye.length > 0) {
						let Clits = this.alpha_sort1(Arrye)
						Clits.map(item => {
							resLi.push({
								children: item
							})
						})
					} else {
						result.push({
							children: element
						})
					}
				}
				result = [...result, ...resget, ...resLi]
				return result;
			},
			checkRepeat(arr, value) {
				var array = [];
				arr.forEach((item) => {
					if (item) {
						array.push(item[value]);
					}
				});
				if ((new Set(array)).size != arr.length) {
					return arr;
				}
				return false;
			},
			alpha_sort1(target) {
				let obj = {},
					result = [],
					resget = [],
					resLi = [];
				target.map((item, index) => {
					let key = item.plandate;
					//如果有这个key，就push一个对象
					if (obj[key]) {
						obj[key].push(item);
						//如果没有这个key，就把对象设置成数组格式（方便后面push进去）
					} else {
						obj[key] = [item];
					}
				});
				//根据obj中有几个对象，挨个push进去，组成最后的数组
				for (const key in obj) {
					// console.log(obj[key]);
					const element = obj[key]
					result.push(
						element
					)
				}
				result = [...result, ...resget, ...resLi]
				console.log(result);
				return result;
			},
			showCS() {
				this.cs++
				if (this.cs >= 10) {
					this.$refs.popup.open('bottom')
					this.cs = 0
				}
			}
		}
	};
</script>

<style scoped lang="scss">
	.ListOfPatients {
		width: 100%;
		height: 100vh;
		overflow: hidden;
	}

	::v-deep.uni-popup {
		.uni-popup__wrapper {
			width: 100%;
			// height: 100%;
			// background-color: #F7F7F7 !important;
		}
	}

	::v-deep .u-form-item__body {
		padding: 4px 0 10px;

		.u-form-item__body__right__content__slot {
			justify-content: space-between;
		}
	}

	.ListOfPatientsBT-center-bottom {
		font-size: 12px;
		font-family: SourceHanSansCN-Normal, SourceHanSansCN;
		font-weight: 400;
		color: #FF4D65;
		line-height: 18px;
	}

	.ListOfPatients_BT {
		// width: 100%;
		// height: 100%;
		display: flex;
		flex-wrap: wrap;
		justify-content: center;
		// padding-top: 10px;
		padding: 10px 10px 10px;
		height: calc(100% - 123px);
		overflow-y: scroll;

		.Patients_BT {
			width: 100%;
			// height: 100%;
		}

		.ListOfPatientsBT_item {
			width: 100%;
			min-height: 50px;
			background: #B0E9EC;
			border-radius: 6px;
			padding-bottom: 7px;
			position: relative;

			&:last-child {
				margin-bottom: 0 !important;
			}

			.view-item {
				width: 50%;
				display: flex;
				align-items: center;
				z-index: 9;
			}

			.view-item1 {
				display: flex;
				align-items: center;
				z-index: 9;
			}

			.ListOfPatientsBTItem_text {
				font-size: 16px;
				font-family: SourceHanSansCN-Medium, SourceHanSansCN;
				font-weight: 500;
				color: #FF4D65;
				line-height: 24px;
				text-align: right;
			}

			.ListOfPatientsBTItem_textT {
				width: 50%;
				font-size: 16px;
				font-family: SourceHanSansCN-Medium, SourceHanSansCN;
				font-weight: 500;
				color: #333333;
				line-height: 24px;
				z-index: 9;
			}

			.textT1 {
				padding-right: 15px;
			}

			.Iage {
				width: 100% !important;
				height: 50% !important;
				position: absolute;
				top: -1px;
				right: 0;
				background-size: auto !important;
				background-position: 100% 0% !important;
				background: url("../../assets/image/sjd.png") no-repeat;
				z-index: 1;
			}
		}

		.ListOfPatientsBT_itemTwo {
			width: 100%;
			min-height: 50px;
			background: #B0E9EC;
			border-radius: 6px;
			position: relative;
			display: flex;
			justify-content: space-between;

			.ListOfPatientsBT_itemTwo_left {
				width: 190px;
				min-height: 50px;
				line-height: 50px;
				display: flex;
				padding: 0 10px;
				// justify-content: space-around;

			}

			.ListOfPatientsBT_itemTwo_right {
				.ListOfPatientsBT_itemTwo_rightSJ {
					position: absolute;
					top: 4px;
					right: 0;
					width: 161px;
					height: 30px;
					z-index: 1;
				}

				.ZXImg {
					position: absolute;
					top: 0;
					right: 0;
					width: 182px !important;
					height: 40px !important;
				}

			}
		}

		.ListOfPatientsBT_center {
			background: #F6FEFF;
			border-radius: 6px;
			opacity: 0.95;
			margin: -3px 6px 0;
			padding: 10px 10px 5px;

			.BT_center_remark {
				font-size: 16px;
				font-family: SourceHanSansCN-Medium, SourceHanSansCN;
				font-weight: 500;
				color: #086168;
				line-height: 24px;
				overflow: hidden;
				display: flex;
				// align-items: center;

				// text-overflow: ellipsis;
				// white-space: nowrap;
				.remark_state {
					color: red;
					margin-right: 5px;
					font-size: 24px;
				}
			}

			.BT_center {
				display: flex;
				align-items: center;

				.text {
					font-size: 14px;
					font-family: SourceHanSansCN-Normal, SourceHanSansCN;
					font-weight: 400;
					// color: #999999;
					line-height: 21px;
					width: 15%;
				}

				.BT_center_hosder {
					display: flex;
					align-items: center;
					font-size: 14px;
					font-family: SourceHanSansCN-Normal, SourceHanSansCN;
					font-weight: 400;
					color: #333333;
					line-height: 21px;
					width: 35%;
					justify-content: space-between;
					// justify-content: right;
				}

				.BT_date {
					width: 50%;
					text-align: right;
					font-size: 14px;
					font-family: SourceHanSansCN-Normal, SourceHanSansCN;
					font-weight: 400;
				}

				color: #333333;
				line-height: 21px;
			}

		}
	}
</style>
